package com.itheima.controller.admin;

import com.itheima.DTO.ArticleDTO;
import com.itheima.DTO.YddArticlePageDTO;
import com.itheima.VO.ArticleVO;
import com.itheima.json.PageBean;
import com.itheima.result.Result;
import com.itheima.service.YddArticleService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
@RequestMapping("/ydd_article")
@Slf4j
public class YddArticleController {

    private final YddArticleService yddArticleService;

    @GetMapping("/list")
    public Result<?> list(YddArticlePageDTO yddArticleDTO){
        PageBean pageBean = yddArticleService.page(yddArticleDTO);
        return Result.success(pageBean);
    }

    @PostMapping("/add")
    public Result<?> add(@RequestBody ArticleDTO articleDTO){
        yddArticleService.insertArticleInfo(articleDTO);
        return Result.success();
    }

    @GetMapping("/rowInfo")
    public Result<?> rowInfo(Integer id){
        ArticleVO articleVO = yddArticleService.selectArticleInfoById(id);
        return Result.success(articleVO);
    }

    @GetMapping("/del")
    public Result<?> delete(Integer id){
        yddArticleService.deleteArticleById(id);
        return Result.success();
    }

    @PostMapping("/update")
    public Result<?> update(@RequestBody ArticleDTO articleDTO){
        yddArticleService.updateArticle(articleDTO);
        return Result.success();
    }
}
